package org.judo.generate.mvc;

public class FileParser implements Parser
{
	Parser nextParser;
	boolean done;
	ParseResults parseResults = new ParseResults();
	
	public ParseResults getParseResults()
	{
		return parseResults;
	}
	
	public Parser getNestedParser()
	{
		return nextParser;
	}

	public boolean needsNestedParser()
	{
		if (nextParser == null)
			return false;
		
		return true;
	}

	public void parseNextLine(String line) 
		throws ParseException
	{
		nextParser = null;
		
		if (line.startsWith("model:"))
		{
			ModelParser parser = new ModelParser();
			parser.setParseResults(parseResults);
			nextParser = parser;
		}
		else if (line.startsWith("view:"))
		{
			ViewParser parser = new ViewParser();
			parser.setParseResults(parseResults);
			nextParser = parser;
		}
		else if (line.startsWith("action:"))
		{
			ActionParser parser = new ActionParser();
			parser.setParseResults(parseResults);
			nextParser = parser;
		}
		else if (line.equals(""))
		{
		}
		else if (line.startsWith("/SCRIPT_END"))
		{
			done = true;
		}
		else
			throw new ParseException("Unexpected token.  Expected either a view or model declaration: "+line);
	}

	public boolean isFinished()
	{
		return done;
	}

	public void setInitLine(String line)
	{		
	}
}
